package edu.mit.media.fv.aqwidgets
{
	import edu.mit.media.fv.layers.Layer;
	import edu.mit.media.fv.blocks.*;
	import edu.mit.media.fv.components.*;
	import edu.mit.media.fv.events.*;
	import edu.mit.media.fv.fluidspace.*;
	import edu.mit.media.fv.icons.*;
	import edu.mit.media.fv.layers.*;
	
	import flash.display.Sprite;
	import flash.display.MovieClip;

	public class AQIncomingTray extends AQWidget
	{
		private var incomingLayer:Layer;
		private var blocks:Object;
		public function AQIncomingTray()
		{
			super();
			this.incomingLayer = new IncomingLayer(-2.0, 0, 0, 600, 70, "Messages", 0x76D980);
			this.addChild(this.incomingLayer);
			this.blocks = new Object();
			FluidEventHandler.addEventListener(UpdateEvent.ADD_POLL, addMessage);
			FluidEventHandler.addEventListener(UpdateEvent.ADD_TEXT, addMessage);
			FluidEventHandler.addEventListener(UpdateEvent.ADD_VOICE, addMessage);
			FluidEventHandler.addEventListener(UpdateEvent.ADD_SHOPPING, addMessage);
			FluidEventHandler.addEventListener(UpdateEvent.ADD_POLL_RESULT, addMessage);
			FluidEventHandler.addEventListener(UpdateEvent.ADD_TIVO, addMessage);
			
		}
		public override function getBlockContainers():Array{
			return [this.incomingLayer];
		}
		public function addMessage(event:UpdateEvent):void{
			var model:Model = Model.getModel(event.id);
			if(model != null){
				// Currently all incoming items are same color, but could be different color
				// TODO: Could form a dictionary based on the type of block
				this.addBlock(model.getBlockInstance(), this.incomingLayer, 0x6DEF7A);
			}
		}
		public function addBlock(block:Block, layer:Layer, color:uint):void{
			block.color = color;
			layer.addBlock(block);
			block.x = layer.layerWidth/2-block.radius;
			this.blocks[block.model.id] = block;
		}
		
	}
}